<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Generates a compact, storable binary representation of a value</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="ref.igbinary.html">« Igbinary 函数</a></li>
      <li style="float: right;"><a href="function.igbinary-unserialize.html">igbinary_unserialize »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.igbinary.html">Igbinary 函数</a></li>
    <li>Generates a compact, storable binary representation of a value</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.igbinary-serialize" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">igbinary_serialize</h1>
  <p class="verinfo">(PECL igbinary &gt;= 1.1.1)</p><p class="refpurpose"><span class="refname">igbinary_serialize</span> &mdash; <span class="dc-title">Generates a compact, storable binary representation of a value</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.igbinary-serialize-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>igbinary_serialize</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   Generates a storable representation of a value.
  </p>
  <p class="para">
   This is useful for storing or passing PHP values around without
   losing their type and structure.
  </p>
  <p class="para">
   To make the serialized string into a PHP value again,
   <span class="function"><a href="function.igbinary-unserialize.html" class="function">igbinary_unserialize()</a></span> can be used.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.igbinary-serialize-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">value</code></dt>

    <dd>

      <p class="para">
       The value to be serialized. <span class="function"><strong>igbinary_serialize()</strong></span>
       handles all types, except the <span class="type">resource</span>-type and some <span class="type">object</span>s (see note below).
       Even <span class="type">array</span>s that contain references to itself can be <span class="function"><strong>igbinary_serialize()</strong></span>d.
       Circular references inside the <span class="type">array</span> or <span class="type">object</span> that is being serializend will also be stored.
       Any other reference will be lost.
      </p>
      <p class="para">
       When serializing objects, igbinary will attempt to call the member functions
       <a href="language.oop5.magic.html#object.serialize" class="link">__serialize()</a> or
       <a href="language.oop5.magic.html#object.sleep" class="link">__sleep()</a> prior to serialization.
       This is to allow the object to do any last minute clean-up, etc. prior
       to being serialized. Likewise, when the object is restored using
       <span class="function"><a href="function.igbinary-unserialize.html" class="function">igbinary_unserialize()</a></span> the <a href="language.oop5.magic.html#object.unserialize" class="link">__unserialize()</a> or
       <a href="language.oop5.magic.html#object.wakeup" class="link">__wakeup()</a> member function is called.
      </p>
      <blockquote class="note"><p><strong class="note">注意</strong>: 
       <p class="para">
        Private members of <span class="type">object</span>s have the class name prepended to the member
        name; protected members have a <code class="literal">&#039;*&#039;</code> prepended to the member name.
        These prepended values have null bytes on either side.
       </p>
      </p></blockquote>
     </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.igbinary-serialize-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a string containing a byte-stream representation of
   <code class="parameter">value</code> that can be stored anywhere.
  </p>
  <p class="para">
   Note that this is a binary string which can include any byte value, and needs
   to be stored and handled as such. For example,
   <span class="function"><strong>igbinary_serialize()</strong></span> output should generally be stored in a <code class="literal">BLOB</code>
   field in a database, rather than a <code class="literal">CHAR</code> or <code class="literal">TEXT</code> field.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.igbinary-serialize-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3404">
    <p><strong>示例 #1 <span class="function"><strong>igbinary_serialize()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$ser&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">igbinary_serialize</span><span style="color: #007700">([</span><span style="color: #DD0000">'test'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'test'</span><span style="color: #007700">]);<br />echo&nbsp;</span><span style="color: #0000BB">urlencode</span><span style="color: #007700">(</span><span style="color: #0000BB">$ser</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">igbinary_unserialize</span><span style="color: #007700">(</span><span style="color: #0000BB">$ser</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
%00%00%00%02%14%02%06%00%11%04test%06%01%0E%00
array (
  0 =&gt; &#039;test&#039;,
  1 =&gt; &#039;test&#039;,
)
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.igbinary-serialize-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    Note that many built-in PHP objects cannot be serialized. However, those with
    this ability either implement the <span class="interfacename"><a href="class.serializable.html" class="interfacename">Serializable</a></span> interface or the
    magic <a href="language.oop5.magic.html#object.serialize" class="link">__serialize()</a>/<a href="language.oop5.magic.html#object.unserialize" class="link">__unserialize()</a>
    or <a href="language.oop5.magic.html#object.sleep" class="link">__sleep()</a>/<a href="language.oop5.magic.html#object.wakeup" class="link">__wakeup()</a> methods. If an
    internal class does not fulfill any of those requirements, it cannot reliably be
    serialized with any serializer.
   </p>
   <p class="para">
    There are some historical exceptions to the above rule, where some internal objects
    could be serialized without implementing the interface or exposing the methods.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.igbinary-serialize-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.serialize.html" class="function" rel="rdfs-seeAlso">serialize()</a> - 生成值的可存储表示</span></li>
    <li class="member"><span class="function"><a href="function.igbinary-unserialize.html" class="function" rel="rdfs-seeAlso">igbinary_unserialize()</a> - Creates a PHP value from a stored representation from igbinary_serialize</span></li>
    <li class="member"><span class="function"><a href="function.var-export.html" class="function" rel="rdfs-seeAlso">var_export()</a> - 输出或返回变量的可解析字符串表示</span></li>
    <li class="member"><span class="function"><a href="function.json-encode.html" class="function" rel="rdfs-seeAlso">json_encode()</a> - 对变量进行 JSON 编码</span></li>
    <li class="member"><a href="language.oop5.serialization.html" class="link">Serializing Objects</a></li>
    <li class="member"><a href="language.oop5.magic.html#object.sleep" class="link">__sleep()</a></li>
    <li class="member"><a href="language.oop5.magic.html#object.wakeup" class="link">__wakeup()</a></li>
    <li class="member"><a href="language.oop5.magic.html#object.serialize" class="link">__serialize()</a></li>
    <li class="member"><a href="language.oop5.magic.html#object.unserialize" class="link">__unserialize()</a></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>